﻿<Window x:Class="winMain"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:res="clr-namespace:Caps.Console.My.Resources"
    xmlns:my="clr-namespace:Caps.Console"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="{x:Static res:Resources.txt_Caps}" Height="600" Width="850" Icon="/CapsConsole;component/Resources/Cap.ico" Name="winMain">
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Close" x:Name="cmdClose"/>
        <CommandBinding Command="ApplicationCommands.New" x:Name="cmdNew"/>
        <CommandBinding Command="NavigationCommands.Refresh" x:Name="cmdRefresh"/> 
    </Window.CommandBindings>
    <Window.Resources>
        <sys:Int32 x:Key="i64">64</sys:Int32>
        <sys:Int32 x:Key="i256">256</sys:Int32>
        <my:ObjectImageConverter x:Key="ObjectImageConverter"/>
        <ItemsPanelTemplate x:Key="HorizontalCapsView">
            <StackPanel Orientation="Horizontal" Height="auto" IsItemsHost="True"  />
        </ItemsPanelTemplate>
        <DataTemplate x:Key="CapView">
            <Grid Margin="3" Width="64" MaxHeight="168" Height="auto" MouseLeftButtonDown="Image_MouseLeftButtonDown"  ToolTipService.ShowDuration="{x:Static sys:Int32.MaxValue}">
                <Grid.RowDefinitions>
                    <RowDefinition MaxHeight="64" Height="auto" SharedSizeGroup="capImgGr"/>
                    <RowDefinition MaxHeight="72" Height="72" SharedSizeGroup="capNameGr"/>
                    <RowDefinition MaxHeight="32" Height="auto" SharedSizeGroup="capIdGr"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="64"/>
                </Grid.ColumnDefinitions>
                <Grid.ToolTip>
                    <Grid Width="256">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="256"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition MaxHeight="256" Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <Image MaxWidth="256" MaxHeight="256" Height="auto" Width="auto"
                            Source="{Binding Path=., Converter={StaticResource ObjectImageConverter}, Mode=OneWay, ConverterParameter={StaticResource i256}}"                               
                            HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0"/>
                        <ItemsControl Grid.Row="1" Grid.Column="0" ItemsSource="{Binding CapSigns, Mode=OneWay}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel HorizontalAlignment="Stretch" VerticalAlignment="Top" MaxWidth="256" Height="auto" Width="auto" IsItemsHost="True"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="32"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="32"/>
                                            <RowDefinition Height="auto" MaxHeight="32"/>
                                        </Grid.RowDefinitions>
                                        <Image MaxWidth="256" MaxHeight="32" Height="auto" Width="auto" Grid.Row="0" Grid.Column="0"
                                            Source="{Binding Path=., Converter={StaticResource ObjectImageConverter}, Mode=OneWay}"/>
                                        <TextBlock Text="{Binding Path=CapName, Mode=OneWay}" Grid.Column="0" Grid.Row="1" TextWrapping="Wrap"/>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </Grid>
                </Grid.ToolTip>
                <Image MaxWidth="64" MaxHeight="64"
                       Source="{Binding Path=., Converter={StaticResource ObjectImageConverter}, Mode=OneWay, ConverterParameter={StaticResource i64}}"
                       HorizontalAlignment="Center" VerticalAlignment="Center" Width="auto" Height="auto"  Grid.Column="0" Grid.Row="0" />
                <TextBlock Grid.Column="0" Grid.Row="1" TextAlignment="Center" HorizontalAlignment="Stretch" VerticalAlignment="Top" Text="{Binding CapName, Mode=OneWay}" TextWrapping="Wrap" MaxWidth="72" FontSize="10" />                   
                <TextBlock Grid.Column="0" Grid.Row="2" TextAlignment="Left" HorizontalAlignment="Stretch" VerticalAlignment="Top" Text="{Binding CapID, Mode=OneWay}" MaxWidth="72" FontSize="10"/>
                <ItemsControl MaxHeight="18" Width="auto" Height="auto" MaxWidth="64" ItemsSource="{Binding CapSigns, Mode=OneWay}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" IsItemsHost="True"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Image MaxWidth="18" MaxHeight="18" Width="auto" Height="auto"
                               Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Bottom"
                               Source="{Binding Path=., Converter={StaticResource ObjectImageConverter}, Mode=OneWay}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
        </DataTemplate>
        <ItemsPanelTemplate x:Key="KwPanel">
            <WrapPanel IsItemsHost="True" Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                       Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}"/>
        </ItemsPanelTemplate> 
        <DataTemplate x:Key="KwItem">
            <TextBlock ToolTip="{Binding Count, Mode=OneWay}" TextBlock.FontSize="{Binding Size, Mode=OneWay}" VerticalAlignment="Center" Margin="10,0,10,0" >
                <Hyperlink Click="Keyword_Click" Focusable="False"><TextBlock Text="{Binding Name, Mode=OneWay}"/></Hyperlink>
            </TextBlock>
        </DataTemplate>
    </Window.Resources>
    <DockPanel >
        <Menu Height="22" Margin="0" Name="mnuMainMenu" VerticalAlignment="Top" DockPanel.Dock="Top"  >
            <MenuItem Header="{x:Static res:Resources.mni_File}" Name="mniFile">
                <MenuItem Header="{x:Static res:Resources.mni_NewCap}" Name="mniNewCap" Command="ApplicationCommands.New">
                    <MenuItem.Icon>
                        <Image Source="/CapsConsole;component/Resources/NewCap.png"/>
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Header="{x:Static res:Resources.mni_Goto}" Name="mniGoto"/>
                <Separator/>
                <MenuItem Header="{x:Static res:Resources.mni_Exit}" Name="mniFileExit" Command="ApplicationCommands.Close" InputGestureText="Alt+F4"/>
            </MenuItem>
            <MenuItem Header="{x:Static res:Resources.mni_Configuration}" Name="mniConfiguration">
                <MenuItem Header="{x:Static res:Resources.mni_EditLists}" Name="mniEditLists" >
                    <MenuItem.Icon>
                        <Image Source="/CapsConsole;component/Resources/EditTableHS.png"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{x:Static res:Resources.mni_Settings}" Name="mniSettings" />
                <MenuItem Header="{x:Static res:Resources.mni_DbSettings}" Name="mniDbSettings" />
            </MenuItem>
            <MenuItem Name="mniTools" Header="{x:Static res:Resources.mni_Tools}">
                <MenuItem Name="mniRefresh"  Header="{x:Static res:Resources.mni_Refresh}" Command="NavigationCommands.Refresh" >
                    <MenuItem.Icon>
                        <Image Source="/CapsConsole;component/Resources/RefreshDocViewHS.png"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Name="mniImagesClear" Header="{x:Static res:Resources.mni_ImagesClear}" ToolTip="{x:Static res:Resources.tot_ImagesClear}" />
                <MenuItem Name="mniSyncImg" Header="{x:Static res:Resources.mni_SyncImages}" ToolTip="{x:Static res:Resources.tot_SyncImages}"/>
            </MenuItem>
            <MenuItem Header="{x:Static res:Resources.mni_Help}"  Name="mniHelp">
                <MenuItem Header="{x:Static res:Resources.mni_About}" Name="mniAbout"/>
            </MenuItem> 
        </Menu>
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/> 
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <GroupBox Header="{x:Static res:Resources.txt_Statistic}" Grid.Column="0" Grid.Row="0" Width="auto">
                <Grid Width="auto" HorizontalAlignment="Center" VerticalAlignment="Center"  >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>    
                    <Grid.RowDefinitions >
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>
                    <Label Grid.Column="0" Grid.Row="0" Content="{x:Static res:Resources.lbl_CapsCount}" HorizontalAlignment="Right"/> 
                    <Label Grid.Column="1" Grid.Row="0" Name="lblCapsCount" HorizontalAlignment="Left"/>
                    <Label Grid.Column="0" Grid.Row="1" Content="{x:Static res:Resources.lbl_OldestCap}" HorizontalAlignment="Right"/>
                    <Label Grid.Column="1" Grid.Row="1" Name="lblOldestcap" HorizontalAlignment="Left"/>
                    <Label Grid.Column="0" Grid.Row="2" Content="{x:Static res:Resources.lbl_NewestCap}" HorizontalAlignment="Right"/>
                    <Label Grid.Column="1" Grid.Row="2" Name="lblNewestCap" HorizontalAlignment="Left"/>
                </Grid>
            </GroupBox> 
            <GroupBox Grid.Column="1" Grid.Row="0">
                <GroupBox.Header>
                    <Hyperlink Name="hylNewest" Focusable="False">
                        <TextBlock Text="{x:Static res:Resources.txt_Newest}" />
                    </Hyperlink>
                </GroupBox.Header>
                <ItemsControl Name="itmNewest" ItemsPanel="{StaticResource HorizontalCapsView}"
                              ItemTemplate="{StaticResource CapView}" HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch" Height="auto" MinHeight="75" IsTabStop="False" Grid.IsSharedSizeScope="True" />
            </GroupBox>
            <GroupBox  Grid.Column="1" Grid.Row="1" Header="{x:Static res:Resources.txt_Random}">
                <ItemsControl Name="itmRandom" ItemsPanel="{StaticResource HorizontalCapsView}"
                              ItemTemplate="{StaticResource CapView}" HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch" Height="auto" MinHeight="75" IsTabStop="False" Grid.IsSharedSizeScope="True"   />
            </GroupBox>
            <Grid Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Height="300">
                <Grid.ColumnDefinitions >
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions >
                    <RowDefinition Height="*" MaxHeight="300"/>
                </Grid.RowDefinitions>
                <GroupBox Grid.Column="0" Grid.Row="0" Header="{x:Static res:Resources.txt_Categories}" VerticalAlignment="Stretch"  HorizontalAlignment="Stretch">
                    <ItemsControl Name="itmCategories" ItemsPanel="{StaticResource KwPanel}" ItemTemplate="{StaticResource KwItem}" IsTabStop="False"
                                  Template="{StaticResource ScrollableItemsControl}"
                                  ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto"
                                  VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                </GroupBox>
                <GroupBox Grid.Column="1" Grid.Row="0" Header="{x:Static res:Resources.txt_Keywords}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
                    <ItemsControl Name="itmKeywords" ItemsPanel="{StaticResource KwPanel}" ItemTemplate="{StaticResource KwItem}" IsTabStop="False"
                                  Template="{StaticResource ScrollableItemsControl}"
                                  ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto"
                                  VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/> 
                </GroupBox>
            </Grid>
        </Grid>
    </DockPanel>
</Window>
